﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using System.Web;
using System.Web.Http.Controllers;
using System.Web.Mvc;
using Barry.BarbeSystem.Core;

namespace Barry.BarbeSystem.Filters
{
    public class CustomerAuthorizationFilter : FilterAttribute, IAuthorizationFilter
    {
        public void OnAuthorization(AuthorizationContext filterContext)
        {
            // var result=   filterContext.RequestContext.HttpContext.Session["hasLogin"];
            HttpCookie loginCookie = filterContext.RequestContext.HttpContext.Request.Cookies["hasLogin"];
            var canLogin = false;



            if (loginCookie != null)
            {
                string login = loginCookie.Values["userID"];
               // string descritLogin = Utility.DecryptDES(login);

                if (login == "admin")
                {
                    canLogin =true;
                }

            }

            
            if (!canLogin)
            {
                filterContext.RequestContext.HttpContext.Response.Redirect("/account/login");
            }

        }
    }
}